import 'package:FiduMart/core/utils/image_constant.dart';
import 'package:FiduMart/core/utils/size_utils.dart';
import 'package:FiduMart/localization/app_export.dart';
import 'package:flutter/material.dart';

import 'appbar_image.dart';
import 'appbar_title.dart';

class BackAppBar extends StatelessWidget implements PreferredSizeWidget {
  BackAppBar({
    Key? key,
    required String this.title,
    this.height = 56,
    this.rightSvg,
    this.rightTap,
    this.leftTap,
    this.arrowleft = true,
  }) : super(key: key);
  String title;
  double height;
  String? rightSvg;
  VoidCallback? rightTap;
  VoidCallback? leftTap;
  bool arrowleft;
  @override
  Widget build(BuildContext context) {
    return CustomAppBar(
        height: getVerticalSize(56),
        leadingWidth: 40,
        leading: arrowleft == false
            ? Container()
            : AppbarImage(
                height: getSize(24),
                width: getSize(24),
                svgPath: ImageConstant.imgArrowleft,
                margin: getMargin(left: 16),
                onTap: leftTap != null
                    ? leftTap
                    : () {
                        Get.back();
                      }),
        centerTitle: true,
        actions: [
          rightSvg == null
              ? Container()
              : GestureDetector(
                  onTap: rightTap,
                  child: CustomImageView(
                    margin: EdgeInsets.only(right: 12),
                    svgPath: rightSvg,
                    height: getSize(
                      34,
                    ),
                    width: getSize(
                      34,
                    ),
                  ),
                ),
        ],
        title: AppbarTitle(text: title));
  }

  @override
  Size get preferredSize => Size(
        size.width,
        height,
      );
}

// ignore: must_be_immutable
class CustomAppBar extends StatelessWidget implements PreferredSizeWidget {
  CustomAppBar({this.height = 56, this.leadingWidth, this.leading, this.title, this.centerTitle, this.actions});

  double height;

  double? leadingWidth;

  Widget? leading;

  Widget? title;

  bool? centerTitle;

  List<Widget>? actions;

  @override
  Widget build(BuildContext context) {
    return AppBar(
      elevation: 0,
      toolbarHeight: height,
      automaticallyImplyLeading: false,
      backgroundColor: Colors.transparent,
      leadingWidth: leadingWidth ?? 0,
      leading: leading,
      title: title,
      titleSpacing: 0,
      centerTitle: centerTitle ?? false,
      actions: actions,
    );
  }

  @override
  Size get preferredSize => Size(
        size.width,
        height,
      );
}
